use crate::core::handling::Rhandler;
use crate::infra;
use crate::services::services_dev;
use crypto_hash::{hex_digest, Algorithm};
// redis api
pub fn dev_0() {
    infra::init_redis();
    // 验证是不是异步
    println!("Data-Handling-check-async...");
    // 测试对象调用程序的正确性
    let redisexec = infra::mredis::RedisExec::new(&infra::mredis::REDISPOOL);
    //redisexec.set(String::from("Hello"), String::from("World"));
    redisexec.get(String::from("Hello"), |result| {
        println!("我是在闭包里面使用的：{:?}", result.as_bytes())
    });
    //redisexec.list_rpush(String::from("BufferList"), String::from("0001"));
    // redisexec.get_list(String::from("BufferList"), |result| {
    //     println!("我在List获取的结果： {}", result);
    //     let redisexec = infra::mredis::RedisExec::new(&infra::mredis::REDISPOOL);
    //     redisexec.set(String::from("Zhang"), String::from("Shulin"));
    // });
}

// 读取redis数据
pub fn dev_services() {
    infra::init_redis();
    infra::init_psql();
    // 验证是不是异步
    println!("Data-Handling-check-async...");
    let redis_handler = Rhandler::new();
    services_dev(redis_handler)
}

// 数据摘要算法
pub fn dev_2() {
    //let data = b"crypto-hash";
    //let result = hex_digest(Algorithm::SHA256, data);
    //let expected = "fd1afb6022cd4d47c890961c533928eacfe8219f1b2524f7fb2a61847ddf8c27";
    let test = "00000001".as_bytes();
    println!("hex digest: {:?}", test)
}

// Postgres test
pub fn dev_3() {
    use infra::mpsql::{PsqlExec, PSQLPOOL};
    infra::init_psql();
    let con = &PSQLPOOL;
    let exec = PsqlExec::new(con);
    let hex = "000000000001".into();
    let info = "xxxxxxx".into();
    let nodeid = "zhangshulin".into();
    let chunkid: i32 = 01;
    exec.inster_hexinfo(hex, info, nodeid, chunkid);
    // exec.get_row_hexinfo(
    //     |a, b, c, d| println!("{},  {:?},   {},  {}", a, b, c, d),
    //     "0000004".into(),
    // );
    // exec.get_rows_hexinfo(|rows| {
    //     for r in rows {
    //         let id: i32 = r.get(0);
    //         let hex: String = r.get(1);
    //         let time: std::time::SystemTime = r.get(2);
    //         let info: String = r.get(3);
    //         let nodeid: String = r.get(4);
    //         println!("{} {} {:?} {} {}",id, hex, time, info, nodeid)
    //     }
    // });
    // exec.my_query_raw("HEXINFO".into(),"HEX".into(),"000000000001".into(),|row|{
    //      let foo: String = row.get("HEX");
    //      println!("HEX : {}",foo)
    // });
}
